package com.example.learn.controller;

import com.example.learn.pojo.FrontKnow;
import com.example.learn.pojo.Plans;
import com.example.learn.service.KnowldService;
import com.example.learn.service.PlanService;
import com.example.learn.utils.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/plan")
public class PlansController {

    @Autowired
    PlanService planService;

    @RequestMapping("/list")
    public R<Map> getPlanList() {
        List<Plans> plansList = planService.getPlanList();
        Map dataMap = new HashMap();
        dataMap.put("data", plansList);
        dataMap.put("total", plansList.size());
        return R.success(dataMap,"success");
    }

    @RequestMapping("/add")
    public R<Map> addPlan(@RequestBody Plans plan) {
        int count = planService.addPlan(plan);
        if(count >= 1){
            return R.success("添加成功");
        }else {
            return R.failed("添加失败");
        }
    }

    @GetMapping("/delete")
    public R delPlanById(String id) {
        int count = planService.delPlanById(id);
        if(count >= 1){
            return R.success("删除成功");
        }else {
            return R.failed("删除失败");
        }
    }

    @GetMapping("/set")
    public R setPlanById(String id) {
        int count = planService.setPlanById(id);
        if(count >= 1){
            return R.success("删除成功");
        }else {
            return R.failed("删除失败");
        }
    }
}
